//
//  ModelDataManager.m
//  3DModelCollector
//
//  Created by Jing Zhang on 7/7/12.
//  Copyright (c) 2012 Tencent. All rights reserved.
//

#import "ModelDataManager.h"
#import "BuildingTask.h"

@interface ModelDataManager()

- (BOOL)initPaths;

@end

static id modelDataInstance = nil;

@implementation ModelDataManager

@synthesize taskList = _taskList;

+ (id)sharedInstance {
    
    if (modelDataInstance == nil) {
        modelDataInstance = [[ModelDataManager alloc] init];
    }
    
    return modelDataInstance;
}

+ (void)destroyInstance {
    
    if (modelDataInstance) {
        [modelDataInstance release];
    }
}

- (id)init {
    
    self = [super init];
    if (self) {
        [self initPaths];
    }
    
    return self;
}

- (void)dealloc {
    self.taskList = nil;
    [super dealloc];
}

- (BOOL)loadTask {
    
    // Parse the white models in input directory
    
    // 
    NSMutableArray* taskList = [[NSMutableArray alloc] init];
    for (int i = 0; i < 10; i++) {
        BuildingTask* oneTask = [[BuildingTask alloc] init];
        switch (i % 3) {
            case 0:
                oneTask.taskState = TS_Fresh;
                break;
                
            case 1:
                oneTask.taskState = TS_Draft;
                break;
                
            case 2:
                oneTask.taskState = TS_Finished;
                break;
                
            default:
                break;
        }
        [taskList addObject:oneTask];
        [oneTask release];
    }
    
    self.taskList = taskList;
    [taskList release];
    
    return YES;
}

#pragma mark - [Private methods]

- (BOOL)initPaths {
    // To do
    
    // 查找whitemodel目录，如果存在，则直接读取，否则，查找zip文件，并进行解压，再读取
/*    
    NSString* docs = [NSHomeDirectory()   stringByAppendingPathComponent:@"Documents"];
    NSString* inputDir = [docs stringByAppendingPathComponent:@"Input"];
    NSFileManager* fileManager = [NSFileManager defaultManager];
    BOOL res = [fileManager createDirectoryAtPath:inputDir withIntermediateDirectories:NO attributes:nil error:nil];
    
    NSString* file = [docs stringByAppendingString:@"whitemodel.dat"];
    res = [fileManager createFileAtPath:file contents:nil attributes:nil];
*/    
    return YES;
}

@end
